//定义4个学生，完成按成绩升序排序
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct student
{
    int IID;
    char NName[20];
    float SScore;
}Stu;
//排序依据
int compByScore(const void *s1, const void *s2)
{
    return ((Stu*)s1)->SScore - ((Stu*)s2)->SScore;
}
//输出
void display(Stu stu[],int len)
{
    int i=0;
    for(i=0;i<len;i++)
    {
        printf("ID:%d\tName:%s\tScore:%g\n",stu[i].IID,stu[i].NName,stu[i].SScore);
    }
}
int main(void)
{
    Stu studata[4]={{1,"ha",80},{2,"hb",54},{3,"hy",91},{4,"ht",69}};
    display(studata,4);
    qsort(studata,4,sizeof(Stu),compByScore);
    printf("\n------------\n");
    printf("按成绩排序后：\n");
    display(studata,4);
    return 0;
}

